﻿using System;
using System.Web.Mvc;
using System.Web.Routing;
using Services.Exceptions;

namespace Socaloud {


    public class MvcApplication : System.Web.HttpApplication {
        protected void Application_Start() {
            AreaRegistration.RegisterAllAreas();

            RouteTable.Routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            RouteTable.Routes.MapHubs();

            RouteTable.Routes.MapRoute(
                name: "Default",
                url: "{controller}/{action}/{id}",
                defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
            );
        }

        protected void Application_Error(Object sender, EventArgs e) {
            var exception = Server.GetLastError();
            if(exception.GetType() == typeof(CustomException))
            {
                Response.ContentType = "application/json";
                Response.StatusCode = 409;
                Response.Output.WriteLine(exception.Message);
                Response.End();
            }
        }
    }
}